package com.software.levelupandroid.utils;

import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;

import com.software.levelupandroid.R;

/**
 * @Description 菜单工具
 * @Author LiangYaJie
 * @CreateTime 2024年05月22日 11:07:46
 */
public class MenuUtil {

    public static void showPopup(View view){
        PopupMenu popup = new PopupMenu(view.getContext(), view);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.item_menu, popup.getMenu());
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()){
                    case R.id.item_edit:
                        return true;
                    case R.id.item_delete:
                        return true;
                    default:
                        return false;
                }
            }
        });
        popup.show();
    }
}
